const express = require("express");

const router = express.Router();

const likeModel = require("../../model/likeModel");

router.post("/addlike", async (req, res) => {
    let { user_id, like_gid } = req.body;
    await likeModel
        .add_like(user_id, like_gid)
        .then((content) => {
            res.send({
                code: 200,
                msg: "收藏成功",
                content,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "收藏失败",
                err,
            });
        });
});

router.post("/notlike", async (req, res) => {
    let { user_id, like_gid } = req.body;
    await likeModel
        .remove_like(user_id, like_gid)
        .then((content) => {
            res.send({
                code: 200,
                msg: "取消收藏成功",
                content,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "取消收藏失败",
                err,
            });
        });
});

router.get("/getlike", async (req, res) => {
    await likeModel
        .get_like()
        .then((content) => {
            res.send({
                code: 200,
                msg: "获取收藏列表成功",
                content,
            });
        })
        .catch((err) => {
            res.send({
                code: -1,
                msg: "获取收餐列表失败",
                err,
            });
        });
});

router.get("/getlikelist", async (req, res) => {
    let { gids } = req.query;
    await likeModel
        .get_like_list(gids)
        .then((content) => {
            res.send({
                code: 200,
                msg: "获取收藏列表数据成功",
                content,
            });
        })
        .catch((error) => {
            res.send({
                code: -1,
                msg: "获取收藏列表数据失败",
                error,
            });
        });
});

module.exports = router;
